package runInfo;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
//import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
//import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
//import org.eclipse.swt.widgets.Composite;
//import org.jfree.experimental.chart.swt.ChartComposite;

//import org.eclipse.swt.SWT;
//import org.eclipse.swt.widgets.Composite;
//import org.eclipse.ui.part.ViewPart;
//import org.jfree.chart.ChartFactory;
//import org.jfree.chart.JFreeChart;
//import org.jfree.chart.plot.PiePlot;
//import org.jfree.data.general.DefaultPieDataset;
//import org.jfree.data.general.PieDataset;
//import org.jfree.experimental.chart.swt.ChartComposite;


import com.phidgets.TemperatureSensorPhidget;

import runInfo.Data;
//import runInfo.mainGui.MeasurementLoop;
//import org.eclipse.swt.custom.ScrolledComposite;
//import org.jfree.chart.JFreeChart;
import org.eclipse.swt.widgets.Group;

public class TestThreadGUI implements Runnable{

    
	private Shell sShell = null;  //  @jve:decl-index=0:visual-constraint="97,44"
	static boolean headerFlag = true;
	public static boolean writeOut = false;

	TemperatureSensorPhidget tempsensor;
	
	public Label tcOut = null;

	public static double tempC = 0.0;
	public static double tempF = 0.0;
	public static double tempAC = 0.0;
	public static double tempAF = 0.0;
    public static int bottling = 0;
	
	public static long t0;
	private Text text1 = null;
	private Text text11 = null;
	private Text text2 = null;
	private ProgressBar progressBar = null;
	private Text coltext11111 = null;
	private Button Plotbutton = null;
	private Text text12 = null;
	private Group Distgroup = null;
	private Text coltext113 = null;
	private Text coltext1113 = null;
	private Text coltext11112 = null;
	private Text corrBrixText = null;
	private Text potenAbvText = null;
	private Text coltext1 = null;
	private Group distGroup = null;
	private Text coltext11121 = null;
	private Text text111 = null;
	private Text coltext2 = null;
	private Text coltext112 = null;
	private Text coltext1112 = null;
	private Combo bottleCombo = null;
	static Combo boilerTempCombo = null;
	static Text measAbvText = null;
	static Combo distTempCombo = null;
	static Text corrAbvText = null;
	private Text coltext111121 = null;
	private Text coltext1111211 = null;
	private Group sensorGroup = null;
	private Text coltext = null;
	private Text coltextC = null;
	private Text temptextA = null;
	private Text temptextC1 = null;
	static Text temptextAC = null;
	static Text tempTextC = null;
	private Text coltextF = null;
	static Text temptextAF = null;
	static Text tempTextF = null;
	private Text temptextC11 = null;
	private Text temptextC111 = null;
	private Text temptextC1111 = null;
	private Button startButton = null;
	private Button stopButton = null;
	private Text coltext11 = null;
	private Text coltext12 = null;
	private Text coltext13 = null;
	private Text mashAbvText = null;
	private Combo OGcombo = null;
	private Combo TGcombo = null;
	private Combo ogTempCombo = null;
	private Combo tgTempCombo = null;
	private Text potenAbvText1 = null;
	
	private void createSShell() {
		GridData gridData2 = new GridData();
		GridData gridData1 = new GridData();
		gridData1.horizontalSpan = 16;
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 20;
		sShell = new Shell();
		sShell.setText("Whiskey");
//		sShell.setImage(new Image(Display.getCurrent(), "C:/WhiskeyData/Complete.bmp"));
		sShell.setFont(new Font(Display.getDefault(), "Segoe UI", 18, SWT.NORMAL));
		sShell.setEnabled(true);
		sShell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		sShell.setLayout(gridLayout);
		sShell.setSize(new Point(1105, 441));
		Label filler1 = new Label(sShell, SWT.NONE);
		createDistgroup();
		createDistGroup();
		createSensorGroup();
		Label filler66 = new Label(sShell, SWT.NONE);
		Label filler11 = new Label(sShell, SWT.NONE);
		Label filler15 = new Label(sShell, SWT.NONE);
		Label filler25 = new Label(sShell, SWT.NONE);
		Label filler569 = new Label(sShell, SWT.NONE);
		Label filler5615 = new Label(sShell, SWT.NONE);
		Label filler13 = new Label(sShell, SWT.NONE);
		Label filler511 = new Label(sShell, SWT.NONE);
		Label filler512 = new Label(sShell, SWT.NONE);
		Label filler38 = new Label(sShell, SWT.NONE);
		Label filler3223 = new Label(sShell, SWT.NONE);
		Label filler3224 = new Label(sShell, SWT.NONE);
		Label filler28 = new Label(sShell, SWT.NONE);
		Label filler34 = new Label(sShell, SWT.NONE);
		Label filler45 = new Label(sShell, SWT.NONE);
		Label filler50 = new Label(sShell, SWT.NONE);
		Label filler2 = new Label(sShell, SWT.NONE);
		text1 = new Text(sShell, SWT.NONE);
		coltext11111 = new Text(sShell, SWT.NONE);
		coltext11111.setEditable(false);
		coltext11111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext11111.setEnabled(false);
		coltext11111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext11111.setText("Ph Temp adjustment");
		Label filler73 = new Label(sShell, SWT.NONE);
		Label filler52 = new Label(sShell, SWT.NONE);
		Label filler60 = new Label(sShell, SWT.NONE);
		Label filler16 = new Label(sShell, SWT.NONE);
		Label filler22 = new Label(sShell, SWT.NONE);
		Label filler5610 = new Label(sShell, SWT.NONE);
		String[] Items = {"0"	,"1"	,"2"	,"3"	,"4"	,"5"	,"6"	,"7"	,"8"	,"9"	,"10"	,"11"	,"12"	,"13"	,"14"	,"15"	,"16"	,"17"	,"18"	,"19"	,"20"	,"21"	,"22"	,"23"	,"24"	,"25"	,"26"	,"27"	,"28"	,"29"	,"30"	,"31"	,"32"	,"33"	,"34"	,"35"	,"36"	,"37"	,"38"	,"39"	,"40"	,"41"	,"42"	,"43"	,"44"	,"45"	,"46"	,"47"	,"48"	,"49"	,"50"	,"51"	,"52"	,"53"	,"54"	,"55"	,"56"	,"57"	,"58"	,"59"	,"60"	,"61"	,"62"	,"63"	,"64"	,"65"	,"66"	,"67"	,"68"	,"69"	,"70"	,"71"	,"72"	,"73"	,"74"	,"75"	,"76"	,"77"	,"78"	,"79"	,"80"	,"81"	,"82"	,"83"	,"84"	,"85"	,"86"	,"87"	,"88"	,"89"	,"90"	,"91"	,"92"	,"93"	,"94"	,"95"	,"96"	,"97"	,"98"	,"99"	,"100"	,"101"	,"102"	,"103"	,"104"	,"105"	,"106"	,"107"	,"108"	,"109"	,"110"	,"111"	,"112"	,"113"	,"114"	,"115"	,"116"	,"117"	,"118"	,"119"	,"120"	,"121"	,"122"	,"123"	,"124"	,"125"	,"126"	,"127"	,"128"	,"129"	,"130"	,"131"	,"132"	,"133"	,"134"	};
		Label filler5616 = new Label(sShell, SWT.NONE);
		boilerTempCombo.select(0);
		Label filler53 = new Label(sShell, SWT.NONE);
		Label filler12 = new Label(sShell, SWT.NONE);
		Label filler47 = new Label(sShell, SWT.NONE);
		Label filler42 = new Label(sShell, SWT.NONE);
		Label filler3225 = new Label(sShell, SWT.NONE);
		Label filler67 = new Label(sShell, SWT.NONE);
		Label filler429 = new Label(sShell, SWT.NONE);
		Label filler55 = new Label(sShell, SWT.NONE);
		Label filler33 = new Label(sShell, SWT.NONE);
		Label filler44 = new Label(sShell, SWT.NONE);
		Label filler3 = new Label(sShell, SWT.NONE);
		text12 = new Text(sShell, SWT.NONE);
		text12.setEnabled(false);
		text12.setEditable(false);
		text12.setText("Plot - abv - bottle");
		text12.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		text12.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		text11 = new Text(sShell, SWT.NONE);
		Label filler93 = new Label(sShell, SWT.NONE);
		Label filler51 = new Label(sShell, SWT.NONE);
		Label filler56 = new Label(sShell, SWT.NONE);
		Label filler14 = new Label(sShell, SWT.NONE);
		Label filler62 = new Label(sShell, SWT.NONE);
		Label filler5611 = new Label(sShell, SWT.NONE);
		Label filler61 = new Label(sShell, SWT.NONE);
		Label filler5 = new Label(sShell, SWT.NONE);
		Label filler59 = new Label(sShell, SWT.NONE);
		Label filler5101 = new Label(sShell, SWT.NONE);
		Label filler37 = new Label(sShell, SWT.NONE);
		Label filler3226 = new Label(sShell, SWT.NONE);
		Label filler3227 = new Label(sShell, SWT.NONE);
		Label filler30 = new Label(sShell, SWT.NONE);
		Label filler31 = new Label(sShell, SWT.NONE);
		Label filler43 = new Label(sShell, SWT.NONE);
		Label filler49 = new Label(sShell, SWT.NONE);
		String[] items = {"1",	"2",	"3",	"4",	"5",	"6",	"7",	"8",	"9",	"10",	"11",	"12",	"13",	"14",	"15",	"16",	"17",	"18",	"19",	"20",	"21",	"22",	"23",	"24",	"25",	"26",	"27",	"28",	"29",	"30",	"31",	"32",	"33",	"34",	"35",	"36",	"37",	"38",	"39",	"40",	"41",	"42",	"43",	"44",	"45",	"46",	"47",	"48",	"49",	"50"};
//		String[] items = {"1 C", "2 C", "3 C", "4 C", "5 C", "6 C", "7 C", "8 C", "9 C", "10 C", "11 C", "12 C", "13 C", "14 C", "15 C", "16 C", "17 C", "18 C", "19 C", "20 C", "21 C", "22 C", "23 C", "24 C", "25 C", "26 C", "27 C", "28 C", "29 C", "30 C", "31 C", "32 C", "33 C", "34 C", "35 C", "36 C", "37 C", "38 C", "39 C", "40 C", "41 C", "42 C", "43 C", "44 C", "45 C", "46 C", "47 C", "48 C", "49 C", "50 C"};
		distTempCombo.select(0);
		text11.setText("Plot - Beginning");
		text11.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		text11.setEnabled(false);
		text11.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		text11.setEditable(false);
		text1.setEditable(false);
		text1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		text1.setEnabled(false);
		text1.setText("Plot - Segment      ");
		text1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		Label filler7 = new Label(sShell, SWT.NONE);
		Label filler10 = new Label(sShell, SWT.NONE);
		text2 = new Text(sShell, SWT.NONE);
		text2.setText("information updating..............                                                                                                      ");
		text2.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		text2.setEnabled(false);
		text2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		text2.setLayoutData(gridData1);
		Label filler40 = new Label(sShell, SWT.NONE);
		Label filler23 = new Label(sShell, SWT.NONE);
		Label filler9 = new Label(sShell, SWT.NONE);
		Plotbutton = new Button(sShell, SWT.NONE);
		Plotbutton.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		Plotbutton.setText("Plot Data");
		progressBar = new ProgressBar(sShell, SWT.NONE);
		progressBar.setLayoutData(gridData2);
		Plotbutton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
//				JFreeChart chart = Plot.CreateChart(tempTCArr,timeS,bottle,boilerTemp);				
//				ChartComposite frame = new ChartComposite(scrolledComposite, SWT.NONE, chart, true);
//				Plot.CreateChart(tempTCArr,timeS,bottle,boilerTemp);
				Plot.CreateChart();
//				scrolledComposite.setBackground(chart);
			}
		});
		distTempCombo.select(0);
		boilerTempCombo.select(0);
		bottleCombo.select(0);
		OGcombo.select(32);
		TGcombo.select(2);
		tgTempCombo.select(25);
		ogTempCombo.select(29);
	}

	static void WriteData(Double runningTime) throws IOException {		//Write out Files ================================================================	
		if(writeOut){
			String Dir = "C:\\WhiskeyData\\output.txt";
			// CheckForHeaderExistance & if beginning time is less than 12 hours...?
			if(headerFlag == true){
					FileWriter write = new FileWriter(Dir, true);
					PrintWriter text = new PrintWriter(write, true);
					String output = "datetime"  
										+ "\t" + "min" 
										+ "\t" + "columnC" 
										+ "\t" + "columnF" 
										+ "\t" + "ambientC" 
										+ "\t" + "ambientF" 
										+ "\t" + "bottleNumber" 
										+ "\t" + "correctedAbv" 
										+ "\t" + "uncorrectedAbv" 
										+ "\t" + "distillateTempC"
										+ "\t" + "boilerTempC"
										+ "\t" + "spaceHere"
										;
					System.out.println(output);
					text.println(output);
					text.flush();
					write.close();
					text.close();
					write = null;
					text = null;
					headerFlag = false;
			}
				try{	
					FileWriter write = new FileWriter(Dir, true);
					PrintWriter text = new PrintWriter(write, true);

			        DecimalFormat df1 = new DecimalFormat("###.##");
//			        DecimalFormat df2 = new DecimalFormat("#####.#####");
//					Double time = (Double.valueOf((System.currentTimeMillis()))-t0)/1000.0/60.0;

					String output = CurrentTime()  	
													+ "\t" + df1.format(runningTime) 
													+ "\t" + Data.tempTC
													+ "\t" + Data.tempTF
													+ "\t" + Data.tempAC
													+ "\t" + Data.tempAF
													+ "\t" + Data.bottleS
													+ "\t" + Data.corrAbvS 
													+ "\t" + Data.measAbvS 
													+ "\t" + Data.distTemp 
													+ "\t" + Data.boilTempS
													;
					System.out.println(output);
					text.println(output);
					text.flush();
					write.close();
					text.close();
					write = null;
					text = null;	
					Data.numOfWrites++;
				}
				catch (IOException ie){		}		
		}
	}
	
	public static String CurrentTime(){
	    Calendar calendar = new GregorianCalendar();
	    String am_pm;
	    int year = calendar.get(Calendar.YEAR);
	    int month = calendar.get(Calendar.MONTH);
	    int day = calendar.get(Calendar.DAY_OF_MONTH); 
	    int hour = calendar.get(Calendar.HOUR);
	    int minute = calendar.get(Calendar.MINUTE);
	    int second = calendar.get(Calendar.SECOND);
	    if(calendar.get(Calendar.AM_PM) == 0)
	    	am_pm = "AM";
	    else{
	    	hour = hour + 12;
	      	am_pm = "PM";
	    }
//      	String times = year + "-" + month  + "-" +day + "\t" + hour + ":"+ minute + ":" + second + " " + am_pm;
//      	String times = year + "-" + month  + "-" +day + " " + hour + ":"+ minute + ":" + second;
      	Data.dateTimeS = year + "-" + month  + "-" +day + " " + hour + ":"+ minute + ":" + second;
	    
      	return Data.dateTimeS;
	  }
//
	@Override
	public void run() {
		Display display = Display.getDefault();
		TestThreadGUI thisClass = new TestThreadGUI();
		thisClass.createSShell();
		thisClass.sShell.open();

		while (!thisClass.sShell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
		
	}

	private void createDistgroup() {
		GridLayout gridLayout1 = new GridLayout();
		gridLayout1.numColumns = 8;
		Distgroup = new Group(sShell, SWT.NONE);
		Distgroup.setText("Fermenting Data");
		Distgroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		Distgroup.setLayout(gridLayout1);
		coltext1 = new Text(Distgroup, SWT.NONE);
		coltext1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext1.setEditable(false);
		coltext1.setText("OG Temperature");
		coltext1.setEnabled(false);
		createOgTempCombo();
		Label filler469 = new Label(Distgroup, SWT.NONE);
		coltext11 = new Text(Distgroup, SWT.NONE);
		coltext11.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext11.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext11.setEditable(false);
		coltext11.setText("OG");
		coltext11.setEnabled(false);
		createOGcombo();
		Label filler57 = new Label(Distgroup, SWT.NONE);
		Label filler72 = new Label(Distgroup, SWT.NONE);
		Label filler4614 = new Label(Distgroup, SWT.NONE);
		coltext113 = new Text(Distgroup, SWT.NONE);
		coltext113.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext113.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext113.setEditable(false);
		coltext113.setText("TG Temperature");
		coltext113.setEnabled(false);
		createTgTempCombo();
		Label filler4610 = new Label(Distgroup, SWT.NONE);
		coltext12 = new Text(Distgroup, SWT.NONE);
		coltext12.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext12.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext12.setEditable(false);
		coltext12.setText("TG");
		coltext12.setEnabled(false);
		createTGcombo();
		Label filler41 = new Label(Distgroup, SWT.NONE);
		Label filler68 = new Label(Distgroup, SWT.NONE);
		Label filler4613 = new Label(Distgroup, SWT.NONE);
		coltext1113 = new Text(Distgroup, SWT.NONE);
		coltext1113.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext1113.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext1113.setEditable(false);
		coltext1113.setText("   ");
		coltext1113.setEnabled(false);
		potenAbvText1 = new Text(Distgroup, SWT.NONE);
		potenAbvText1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		potenAbvText1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		potenAbvText1.setEditable(false);
		potenAbvText1.setText("  ");
		potenAbvText1.setEnabled(false);
		corrBrixText = new Text(Distgroup, SWT.NONE);
		corrBrixText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		corrBrixText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		corrBrixText.setEditable(false);
		corrBrixText.setText("  ");
		corrBrixText.setEnabled(false);
		Label filler4615 = new Label(Distgroup, SWT.NONE);
		Label filler3216 = new Label(Distgroup, SWT.NONE);
		Label filler39 = new Label(Distgroup, SWT.NONE);
		Label filler65 = new Label(Distgroup, SWT.NONE);
		Label filler71 = new Label(Distgroup, SWT.NONE);
		coltext11112 = new Text(Distgroup, SWT.NONE);
		coltext11112.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext11112.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext11112.setEditable(false);
		coltext11112.setText("  ");
		coltext11112.setEnabled(false);
		potenAbvText = new Text(Distgroup, SWT.NONE);
		potenAbvText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		potenAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		potenAbvText.setEditable(false);
		potenAbvText.setText("  ");
		potenAbvText.setEnabled(false);
		Label filler27 = new Label(Distgroup, SWT.NONE);
		coltext13 = new Text(Distgroup, SWT.NONE);
		coltext13.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext13.setEditable(false);
		coltext13.setText("abv");
		coltext13.setEnabled(false);
		coltext13.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		mashAbvText = new Text(Distgroup, SWT.NONE);
		mashAbvText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		mashAbvText.setEditable(false);
		mashAbvText.setText("000.00");
		mashAbvText.setEnabled(false);
		mashAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		Label filler64 = new Label(Distgroup, SWT.NONE);
		Label filler70 = new Label(Distgroup, SWT.NONE);
		Label filler4612 = new Label(Distgroup, SWT.NONE);
		coltext111121 = new Text(Distgroup, SWT.NONE);
		coltext111121.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext111121.setFont(new Font(Display.getDefault(), "Segoe UI", 12, SWT.NORMAL));
		coltext111121.setEditable(false);
		coltext111121.setText("    ");
		coltext111121.setEnabled(false);
		Label filler20 = new Label(Distgroup, SWT.NONE);
		Label filler26 = new Label(Distgroup, SWT.NONE);
		Label filler29 = new Label(Distgroup, SWT.NONE);
		Label filler35 = new Label(Distgroup, SWT.NONE);
		Label filler58 = new Label(Distgroup, SWT.NONE);
		Label filler69 = new Label(Distgroup, SWT.NONE);
		Label filler4611 = new Label(Distgroup, SWT.NONE);
		coltext1111211 = new Text(Distgroup, SWT.NONE);
		coltext1111211.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext1111211.setFont(new Font(Display.getDefault(), "Segoe UI", 12, SWT.NORMAL));
		coltext1111211.setEditable(false);
		coltext1111211.setText("   ");
		coltext1111211.setEnabled(false);
	}

	/**
	 * This method initializes distGroup	
	 *
	 */
	private void createDistGroup() {
		GridLayout gridLayout2 = new GridLayout();
		gridLayout2.numColumns = 2;
		distGroup = new Group(sShell, SWT.NONE);
		distGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		distGroup.setText("Distilling Data");
		distGroup.setLayout(gridLayout2);
		coltext11121 = new Text(distGroup, SWT.NONE);
		coltext11121.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext11121.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext11121.setEditable(false);
		coltext11121.setText("Bottle #");
		coltext11121.setEnabled(false);
		createBottleCombo();
		text111 = new Text(distGroup, SWT.NONE);
		text111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		text111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		text111.setEditable(false);
		text111.setText("boiler temp");
		text111.setEnabled(false);
		createBoilerTempCombo();
		coltext2 = new Text(distGroup, SWT.NONE);
		coltext2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext2.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext2.setEditable(false);
		coltext2.setText("Measured abv");
		coltext2.setEnabled(false);
		measAbvText = new Text(distGroup, SWT.BORDER);
		measAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		measAbvText.setText("000.0");
		measAbvText.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
			public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
				corrAbvText.setText(String.valueOf(TempCorrections.GetABV(Double.valueOf(measAbvText.getText()), distTempCombo.getText())));
			}
		});
		coltext112 = new Text(distGroup, SWT.NONE);
		coltext112.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext112.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext112.setEditable(false);
		coltext112.setText("Distillate Temp");
		coltext112.setEnabled(false);
		createDistTempCombo();
		coltext1112 = new Text(distGroup, SWT.NONE);
		coltext1112.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext1112.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext1112.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
		coltext1112.setEditable(false);
		coltext1112.setText("Corrected abv");
		coltext1112.setEnabled(false);
		corrAbvText = new Text(distGroup, SWT.NONE);
		corrAbvText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		corrAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		corrAbvText.setEditable(false);
		corrAbvText.setText("000.00");
		corrAbvText.setEnabled(false);
	}

	/**
	 * This method initializes bottleCombo	
	 *
	 */
	private void createBottleCombo() {
		bottleCombo = new Combo(distGroup, SWT.NONE);
		bottleCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		bottleCombo.setText("000");
		String[] bottleItems = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"};
		bottleCombo.setItems(bottleItems);
		bottleCombo
				.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
					public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
						Data.bottleS = bottleCombo.getText();
					}
					public void widgetDefaultSelected(
							org.eclipse.swt.events.SelectionEvent e) {
					}
				});
	}

	/**
	 * This method initializes boilerTempCombo	
	 *
	 */
	private void createBoilerTempCombo() {
		boilerTempCombo = new Combo(distGroup, SWT.NONE);
		boilerTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		String[] Items = {"0"	,"1"	,"2"	,"3"	,"4"	,"5"	,"6"	,"7"	,"8"	,"9"	,"10"	,"11"	,"12"	,"13"	,"14"	,"15"	,"16"	,"17"	,"18"	,"19"	,"20"	,"21"	,"22"	,"23"	,"24"	,"25"	,"26"	,"27"	,"28"	,"29"	,"30"	,"31"	,"32"	,"33"	,"34"	,"35"	,"36"	,"37"	,"38"	,"39"	,"40"	,"41"	,"42"	,"43"	,"44"	,"45"	,"46"	,"47"	,"48"	,"49"	,"50"	,"51"	,"52"	,"53"	,"54"	,"55"	,"56"	,"57"	,"58"	,"59"	,"60"	,"61"	,"62"	,"63"	,"64"	,"65"	,"66"	,"67"	,"68"	,"69"	,"70"	,"71"	,"72"	,"73"	,"74"	,"75"	,"76"	,"77"	,"78"	,"79"	,"80"	,"81"	,"82"	,"83"	,"84"	,"85"	,"86"	,"87"	,"88"	,"89"	,"90"	,"91"	,"92"	,"93"	,"94"	,"95"	,"96"	,"97"	,"98"	,"99"	,"100"	,"101"	,"102"	,"103"	,"104"	,"105"	,"106"	,"107"	,"108"	,"109"	,"110"	,"111"	,"112"	,"113"	,"114"	,"115"	,"116"	,"117"	,"118"	,"119"	,"120"	,"121"	,"122"	,"123"	,"124"	,"125"	,"126"	,"127"	,"128"	,"129"	,"130"	,"131"	,"132"	,"133"	,"134"	};
		boilerTempCombo.setItems(Items);
		boilerTempCombo.setText("000");
	}

	private void createDistTempCombo() {
		distTempCombo = new Combo(distGroup, SWT.NONE);
		distTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		String[] Items = {"0"	,"1"	,"2"	,"3"	,"4"	,"5"	,"6"	,"7"	,"8"	,"9"	,"10"	,"11"	,"12"	,"13"	,"14"	,"15"	,"16"	,"17"	,"18"	,"19"	,"20"	,"21"	,"22"	,"23"	,"24"	,"25"	,"26"	,"27"	,"28"	,"29"	,"30"	,"31"	,"32"	,"33"	,"34"	,"35"	,"36"	,"37"	,"38"	,"39"	,"40"	,"41"	,"42"	,"43"	,"44"	,"45"	,"46"	,"47"	,"48"	,"49"	,"50"};
		distTempCombo.setItems(Items);
		distTempCombo.setText("1.000");
		distTempCombo
				.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
					public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
						corrAbvText.setText(String.valueOf(TempCorrections.GetABV(Double.valueOf(measAbvText.getText()), distTempCombo.getText())));
					}
					public void widgetDefaultSelected(
							org.eclipse.swt.events.SelectionEvent e) {
					}
				});
	}

	private void createSensorGroup() {
		GridLayout gridLayout3 = new GridLayout();
		gridLayout3.numColumns = 4;
		sensorGroup = new Group(sShell, SWT.NONE);
		sensorGroup.setText("Temperature Sensor");
		sensorGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		sensorGroup.setLayout(gridLayout3);
		coltext = new Text(sensorGroup, SWT.NONE);
		coltext.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltext.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltext.setEditable(false);
		coltext.setText("Sensor");
		coltext.setEnabled(false);
		coltextC = new Text(sensorGroup, SWT.CENTER);
		coltextC.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltextC.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltextC.setEditable(false);
		coltextC.setText("C");
		coltextC.setEnabled(false);
		coltextF = new Text(sensorGroup, SWT.CENTER);
		coltextF.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		coltextF.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		coltextF.setEditable(false);
		coltextF.setText("F");
		coltextF.setEnabled(false);
		Label filler21 = new Label(sensorGroup, SWT.NONE);
		temptextA = new Text(sensorGroup, SWT.NONE);
		temptextA.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		temptextA.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		temptextA.setEditable(false);
		temptextA.setText("Board: ");
		temptextA.setEnabled(false);
		temptextAC = new Text(sensorGroup, SWT.NONE);
		temptextAC.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		temptextAC.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		temptextAC.setEditable(false);
		temptextAC.setText("000.000");
		temptextAC.setEnabled(false);
		temptextAF = new Text(sensorGroup, SWT.NONE);
		temptextAF.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		temptextAF.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		temptextAF.setEditable(false);
		temptextAF.setText("000.000");
		temptextAF.setEnabled(false);
		Label filler19 = new Label(sensorGroup, SWT.NONE);
		temptextC1 = new Text(sensorGroup, SWT.WRAP);
		temptextC1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		temptextC1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		temptextC1.setEditable(false);
		temptextC1.setText("Thermocouple:    ");
		temptextC1.setEnabled(false);
		tempTextC = new Text(sensorGroup, SWT.NONE);
		tempTextC.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		tempTextC.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		tempTextC.setEditable(false);
		tempTextC.setText("000.000");
		tempTextC.setEnabled(false);
		tempTextF = new Text(sensorGroup, SWT.NONE);
		tempTextF.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		tempTextF.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		tempTextF.setEditable(false);
		tempTextF.setText("000.000");
		tempTextF.setEnabled(false);
		Label filler18 = new Label(sensorGroup, SWT.NONE);
		temptextC11 = new Text(sensorGroup, SWT.WRAP);
		temptextC11.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		temptextC11.setFont(new Font(Display.getDefault(), "Segoe UI", 9, SWT.NORMAL));
		temptextC11.setEditable(false);
		temptextC11.setText("   ");
		temptextC11.setEnabled(false);
		Label filler = new Label(sensorGroup, SWT.NONE);
		Label filler4 = new Label(sensorGroup, SWT.NONE);
		Label filler17 = new Label(sensorGroup, SWT.NONE);
		startButton = new Button(sensorGroup, SWT.NONE);
		startButton.setText("Start Recording");
		startButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		startButton.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		startButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				writeOut = true;
			}
		});
		temptextC111 = new Text(sensorGroup, SWT.WRAP);
		temptextC111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		temptextC111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		temptextC111.setEditable(false);
		temptextC111.setText("  ");
		temptextC111.setEnabled(false);
		Label filler6 = new Label(sensorGroup, SWT.NONE);
		Label filler8 = new Label(sensorGroup, SWT.NONE);
		stopButton = new Button(sensorGroup, SWT.NONE);
		stopButton.setText("Stop Recording");
		stopButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		stopButton.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		stopButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				writeOut = false;
			}
		});
		temptextC1111 = new Text(sensorGroup, SWT.WRAP);
		temptextC1111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		temptextC1111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		temptextC1111.setEditable(false);
		temptextC1111.setText("  ");
		temptextC1111.setEnabled(false);
	}

	private void createOGcombo() {
		OGcombo = new Combo(Distgroup, SWT.NONE);
		OGcombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		String[] Items = {"1.000",	"1.002",	"1.005",	"1.007",	"1.010",	"1.012",	"1.015",	"1.017",	"1.020",	"1.022",	"1.025",	"1.0275",	"1.030",	"1.032",	"1.035",	"1.037",	"1.040",	"1.042",	"1.045",	"1.047",	"1.050",	"1.052",	"1.055",	"1.057",	"1.060",	"1.062",	"1.065",	"1.067",	"1.070",	"1.072",	"1.075",	"1.077",	"1.080",	"1.082",	"1.085",	"1.087",	"1.090",	"1.092",	"1.095",	"1.097",	"1.100"};
		OGcombo.setItems(Items);
		OGcombo.setText("1.000");
		OGcombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
				Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
		        DecimalFormat df1 = new DecimalFormat("#.####");
				mashAbvText.setText(String.valueOf(df1.format((og-tg)*105*1.25)));
		}
			public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {}
		});
	}

	private void createTGcombo() {
		TGcombo = new Combo(Distgroup, SWT.NONE);
		TGcombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		String[] Items = {"1.000",	"1.002",	"1.005",	"1.007",	"1.010",	"1.012",	"1.015",	"1.017",	"1.020",	"1.022",	"1.025",	"1.0275",	"1.030",	"1.032",	"1.035",	"1.037",	"1.040",	"1.042",	"1.045",	"1.047",	"1.050",	"1.052",	"1.055",	"1.057",	"1.060",	"1.062",	"1.065",	"1.067",	"1.070",	"1.072",	"1.075",	"1.077",	"1.080",	"1.082",	"1.085",	"1.087",	"1.090",	"1.092",	"1.095",	"1.097",	"1.100"};
		TGcombo.setItems(Items);
		TGcombo.setText("1.000");
		TGcombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
				Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
		        DecimalFormat df1 = new DecimalFormat("#.####");
				mashAbvText.setText(String.valueOf(df1.format((og-tg)*105*1.25)));
		}
			public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
			}
		});
	}

	private void createOgTempCombo() {
		ogTempCombo = new Combo(Distgroup, SWT.NONE);
		ogTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		String[] Items = {"0"	,"1"	,"2"	,"3"	,"4"	,"5"	,"6"	,"7"	,"8"	,"9"	,"10"	,"11"	,"12"	,"13"	,"14"	,"15"	,"16"	,"17"	,"18"	,"19"	,"20"	,"21"	,"22"	,"23"	,"24"	,"25"	,"26"	,"27"	,"28"	,"29"	,"30"	,"31"	,"32"	,"33"	,"34"	,"35"	,"36"	,"37"	,"38"	,"39"	,"40"	,"41"	,"42"	,"43"	,"44"	,"45"	,"46"	,"47"	,"48"	,"49"};
		ogTempCombo.setItems(Items);
		ogTempCombo.setText("1.000");
		ogTempCombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
				Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
		        DecimalFormat df1 = new DecimalFormat("#.####");
				mashAbvText.setText(String.valueOf(df1.format((og-tg)*105*1.25)));
		}
			public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
			}
		});
	}

	private void createTgTempCombo() {
		tgTempCombo = new Combo(Distgroup, SWT.NONE);
		tgTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
		String[] Items = {"0"	,"1"	,"2"	,"3"	,"4"	,"5"	,"6"	,"7"	,"8"	,"9"	,"10"	,"11"	,"12"	,"13"	,"14"	,"15"	,"16"	,"17"	,"18"	,"19"	,"20"	,"21"	,"22"	,"23"	,"24"	,"25"	,"26"	,"27"	,"28"	,"29"	,"30"	,"31"	,"32"	,"33"	,"34"	,"35"	,"36"	,"37"	,"38"	,"39"	,"40"	,"41"	,"42"	,"43"	,"44"	,"45"	,"46"	,"47"	,"48"	,"49"};
		tgTempCombo.setItems(Items);
		tgTempCombo.setText("1.000");		
		tgTempCombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {

			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
				Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
		        DecimalFormat df1 = new DecimalFormat("#.####");
				mashAbvText.setText(String.valueOf(df1.format((og-tg)*105*1.25)));
		}
			public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
			}
		});
	}

}
